package com.qinglei.recoup.third.controller;

import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.common.exception.RecoupException;
import com.qinglei.recoup.third.domain.dto.RadarAddDto;
import com.qinglei.recoup.third.service.FuXingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 复星控制层
 *
 * @author yujunwei
 * @datetime 2022-05-04 20:46
 */
@Api(tags = "复星相关操作")
@RequestMapping("/fuxing")
@RestController
@Slf4j
public class FuXingController {

    @Autowired
    private FuXingService fuXingService;

    @ApiOperation(value = "添加监测仪")
    @PostMapping("/radar")
    public CommonRes<Object> add(@RequestBody @Valid RadarAddDto radarAddDto) {
        try {
            fuXingService.add(radarAddDto);
        } catch (RecoupException e) {
            log.error("添加监测仪失败", e);
            return CommonRes.failed(e.getMessage());
        }
        return CommonRes.ok("添加监测仪成功");
    }

}
